using MyStatus;
using Services;
using UnityEngine;

[RequireComponent(typeof(PointTrigger_Character))]
public class Trap : MonoBehaviour
{
    private PointTrigger_Character trigger;
    private Player player;

    [SerializeField]
    private float damage;
    [SerializeField]
    private float duration_status;
    [SerializeField]
    private Status status;

    private void Awake()
    {
        player = ServiceLocator.Get<ActionController>().player;
        trigger = GetComponent<PointTrigger_Character>();
        trigger.OnTriggerEnter += MyOnTriggerEnter;
    }

    private void MyOnTriggerEnter(Character character)
    {
        if (character == player)
            return;
        character.TakeDamage(null, damage, EDamageType.Sharp);
        character.StatusManager.AddStatus(new RuntimeStatus(duration_status, status));
        Destroy(gameObject);
    }
}
